procedure genPerm(s : string);
 
var
	i, j, ps, r, l : longint;
 
begin       
	sort(s, 1, n); // if ALL permutations are required
	ps := 1;	
	while ps > 0 do begin
		ps := n - 1;
		writeln(s);
		i := n;
		while (ps > 0) and (s[ps] >= s[i]) do begin
			dec(ps);
			dec(i);
		end;
		j := n;
		while (ps > 0) and (j > 0) and (s[ps] >= s[j]) do dec(j);
		if ps > 0 then swap(s[ps], s[j]);
		l := ps + 1;
		r := n;
		while r > l do begin
			swap(s[l], s[r]);
			inc(l);
			dec(r);
		end;
	end;
end;